<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/pub/headmeta.jsp"%>
</head>
<body>
	<div class="right-head">
		<span class="right-head-font">消息订单</span>
	</div>

	<form id="queryForm" method="post">
		<div class="term">
			<div class="div1-2">消息内容：</div>
			<div class="div2"><input type="text" name="q_content" id="q_content" /></div>
			<div class="div1-2">创建者：</div>
			<div class="div2"><input type="text" name="q_creator" id="q_creator" /></div>			
			<br style="clear: both;" />
			<br />
			<div class="div1-2">下发者：</div>
			<div class="div2"><input type="text" name="q_sendor" id="q_sendor" /></div>
			<br style="clear: both;" />
			<br />
		</div>
		<div class="function-bar">
			<div class="div0"><input type="button" class="button-bar" value="重置条件" 	onclick="resetEx(this.form);" /></div>			
			<div class="div0"><input type="button" class="button-bar" value="查询" onclick="setCurPage(1);doQuery();" /></div>
		</div>
	</form>

	<form id="delForm" method="post">
		<table id="MyTableList" width="100%" border="0" align="center"
			cellpadding="0" cellspacing="0" class="table-form">
			<tr align="center" class="STYLE1">
				<th width="5%"><input id="ckAll" type="checkbox" onclick="checkAll(this.checked,'cb');" /></th>
				<th width="5%">序号</th>
				<th width="25%">消息内容</th>
				<th width="10%">接收群</th>
				<th width="10%">创建者</th>
				<th width="10%">创建时间</th>
				<th width="10%">下发者</th>
				<th width="10%">下发时间</th>
				<th width="15%">操作</th>
			</tr>
		</table>
		<%@ include file="/pub/pageLink.jsp"%>
	</form>
</body>
</html>
<script type="text/javascript">
<!--
	//自动调用初始化
	$(document).ready(function() {
		//查询
		doQuery();
	});

	//查询
	function doQuery() {
		var page = getPage();
		var pageSize = getPageSize();
		var url = "${ctx}/msgOrder!getList.action?page=" + page + "&pageSize=" + pageSize;
		$.post(url, $("#queryForm").serialize(), function callback(txt) {
			var json = $.parseJSON(txt);
			if (json.code == 0) {
				setRecordCount(json.count);
				createTable(json.info, page, pageSize);
			} else {
				alert('查询失败！');
			}
		});
	}

	//创建表数据
	function createTable(objs, page, pageSize) {
		var table = document.getElementById('MyTableList');
		for ( var i = table.rows.length - 1; i > 0; i--) {
			table.deleteRow(i);
		}
		var b = document.createElement("tbody");
		for ( var i = 0; i < objs.length; i++) {
			var obj = objs[i];
			var row = document.createElement("tr");
			row.align = "center";

			var c1 = document.createElement("td");
			c1.innerHTML = "<input name='cb' type='checkbox' value='"+obj.orderId+"'/>";
			var c2 = document.createElement("td");
			c2.innerHTML = (page - 1) * pageSize + i + 1;
			var c3 = document.createElement("td");
			c3.innerHTML = obj.content;
			var c4 = document.createElement("td");
			c4.innerHTML = obj.groupName;
			var c5 = document.createElement("td");
			c5.innerHTML = obj.creator;
			var c6 = document.createElement("td");
			if(obj.createTime){
				c6.innerHTML = formatDate(obj.createTime);
			}
			var c7 = document.createElement("td");
			c7.innerHTML = obj.sendor;
			var c8 = document.createElement("td");
			if(obj.sendTime){
				c8.innerHTML = formatDate(obj.sendTime);
			}
			var c9=document.createElement("td");
			if(obj.alreadySend){
				c9.innerHTML="已下发";
			}else{
				c9.innerHTML="<input type='button' class='button-bar' value='下发' onclick='dosinglesend(\""+obj.orderId+"\");' ${f:op(ops,'消息订单','下发')}/>";
			}

			row.appendChild(c1);
			row.appendChild(c2);
			row.appendChild(c3);
			row.appendChild(c4);
			row.appendChild(c5);
			row.appendChild(c6);
			row.appendChild(c7);
			row.appendChild(c8);
			row.appendChild(c9);
			setTdStyle(row);
			b.appendChild(row);
		}
		table.appendChild(b);
	}
	
	//单条下发
	function dosinglesend(id){
		var param = "orderId="+id;
		sendmsg(param);
	}
	
	//发送消息
	function sendmsg(params){
		if(confirm('确认已经发送完消息？')){			
			$.post("${ctx}/msgOrder!sendmsg.action",
					params,
					function callback(txt) {
					var json = $.parseJSON(txt);
					if (json.success == true) {						
						doQuery();
					} else {
						alert('确认失败！');
					}
			});
		}
	}
	
	//批量下发
	function batchsendmsg(){
		if(ifCheck('cb')){
			if(confirm('确定要删除选中的记录吗？')){
				var rows = $("input[name=cb]:checked");
				/* 将选择的对象序列化为字符串参数 */
			    var parameters = "";
			    rows.each(function() {
					parameters += "&orderId=" + $(this).val();
				});
				parameters = parameters.substr(1);
				sendmsg(parameters);
			}
		}else{
			alert('请先勾选记录！');
		}
	}
//-->
</script>
